package org.example.javadt.service;


import jakarta.servlet.http.HttpServletRequest;
import org.example.javadt.entity.posts;
import org.example.javadt.entity.wusers;
import org.example.javadt.mapperjiekou.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class data {
    @Autowired
    private commp commp;
    @Autowired
    private likemp likemp;
    @Autowired
    private posmp posmp;
    @Autowired
    private postagmp postagmp;
    @Autowired
    private tagmp tagmp;
    @Autowired
    private wusermp wusermp;

    @RequestMapping("/dat")
    public List<wusers> seletwusermp(HttpServletRequest request) {
        Integer page = Integer.parseInt(request.getParameter("page"));
        String tag_name = request.getParameter("tag_name");
        System.out.println(page);
        System.out.println(tag_name);
        page = (page - 1) * 100;

//        System.out.println(page);
//        System.out.println(wusermp.selectall(page, tag_name));
        return wusermp.selectall(page, tag_name);
    }

    @RequestMapping("/count")
    public int seletcount(HttpServletRequest request) {
        String tag_name = request.getParameter("tag_name");
        Integer count = wusermp.wusercount(tag_name) / 100;
        System.out.println(count);
        return count;
    }

    @RequestMapping("/post")
    public List<posts> seletposts() {
        return posmp.selectall();
    }

    @RequestMapping("/coms")
    public List<wusers> selectpl(HttpServletRequest request) {
        String post_id = request.getParameter("post_id");
        System.out.println(post_id);
        return wusermp.selectpl(post_id);
    }
}
